# Replication Code for "Perceived Opposition to Racially Progressive Policies 
# and Negative Affect toward the Republican Party among Democrats"

# Tyler Reny, Kirill Zhirkov, and Byengseon Bae
# Forthcoming at JREP
# Please contact Byengseon for any questions
# byengseon.bae@cgu.edu

# Packages

library(tidyverse)
library(cregg)
library(broom)
library(dotwhisker)

# Data 

df_amce <- read_csv("df_amce.csv")
df_imce <- read_csv("df_imce.csv")

# Making factor variables for attributes
df_amce$conj_older <- factor(df_amce$conj_older, 
                             levels = c("Young", "Old"))
df_amce$conj_males <- factor(df_amce$conj_males, 
                             levels = c("Female", "Male"))
df_amce$conj_white <- factor(df_amce$conj_white, 
                             levels = c("Non-White", "White"))
df_amce$conj_nocol <- factor(df_amce$conj_nocol, 
                             levels = c("College", "No College"))
df_amce$conj_smgov <- factor(df_amce$conj_smgov, 
                             levels = c("Economically Liberal", "Economically Conservative"))
df_amce$conj_relgs <- factor(df_amce$conj_relgs, 
                             levels = c("Non-Religious", "Religious"))
df_amce$conj_noeql <- factor(df_amce$conj_noeql, 
                             levels = c("Racially Liberal", "Racially Conservative"))
df_amce$conj_upper <- factor(df_amce$conj_upper, 
                             levels = c("Middle/Working Class", "Upper Class"))
df_amce$conj_badpr <- factor(df_amce$conj_badpr, 
                             levels = c("Positive Traits", "Negative Traits"))
df_amce$pid_white <- factor(df_amce$pid_white, 
                            levels = c("White Democrat","Non-White Democrat","White Republican"))
df_amce$white <- factor(df_amce$white, 
                        levels = c("White", "Non-White"))
df_amce$pid3_new <- factor(df_amce$pid3_new, 
                           levels = c("Democrat","Independent","Republican"))
df_amce$pid_white2 <- factor(df_amce$pid_white2, 
                             levels = c("White Democrat","Non-White Democrat","White Republican","Non-White Republican"))
df_amce$pid_wbo <- factor(df_amce$pid_wbo, 
                          levels = c("White Democrat","Black Democrat","Other Democrat"))
df_amce$rr_scale_cat2 <- factor(df_amce$rr_scale_cat2, 
                                levels = c("Low Racial Resentment","High Racial Resentment"))
df_amce$ar_scale_cat2 <- factor(df_amce$ar_scale_cat2, 
                                levels = c("Low Anti Racism","High Anti Racism")) 
df_amce$pid_white_rr <- factor(df_amce$pid_white_rr, 
                               levels = c("White Democrat with Low RR","White Democrat with High RR","Non-White Democrat with Low RR","Non-White Democrat with High RR","White Republican with Low RR","White Republican with High RR"))
df_amce$pid_white_ar <- factor(df_amce$pid_white_ar, 
                               levels = c("White Democrat with Low AR","White Democrat with High AR","Non-White Democrat with Low AR","Non-White Democrat with High AR","White Republican with Low AR","White Republican with High AR"))

##############
## Figure 1 ##
##############

# White Democrat

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + 
           conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, 
         id = ~respid, estimate = "amce", by = ~pid_white)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

n1 <- as.data.frame(c("White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level",
                  "estimate","std.error","z","p","lower","upper","BY2")

# Non-White Democrat
n1 <- as.data.frame(c("Non-White Democrat","Non-White Democrat",
                      "Non-White Democrat","Non-White Democrat",
                      "Non-White Democrat","Non-White Democrat",
                      "Non-White Democrat","Non-White Democrat",
                      "Non-White Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology",
                      "Religiosity", "Racial Ideology", "Social Class", 
                      "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:",
                      "Economic Ideology:", "Religiosity:", "Racial Ideology:",
                      "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate",
                  "std.error","z","p","lower","upper","BY2")

# White Republican

n1 <- as.data.frame(c("White Republican","White Republican","White Republican",
                      "White Republican","White Republican","White Republican",
                      "White Republican","White Republican","White Republican"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology",
                      "Religiosity", "Racial Ideology", "Social Class", 
                      "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", 
                      "Economic Ideology:", "Religiosity:", "Racial Ideology:",
                      "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m4 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m4) <- c("BY","outcome","statistic","feature","level","estimate",
                  "std.error","z","p","lower","upper","BY2")

pid <- rbind(m1,m2,m3,m4)
pid$BY <- factor(pid$BY, levels = c("White Democrat","Non-White Democrat",
                                    "White Republican"))

a <- pid %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, 
                                                          levels = c("Age:", "     Old", "     Young",
                                                                            "Gender:", "     Male","     Female",
                                                                            "Race:","     White","     Non-White",
                                                                            "Education:","     No College","     College",
                                                                            "Religiosity:","     Religious","     Non-Religious",
                                                                            "Social Class:","     Upper Class","     Middle/Working Class",
                                                                            "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                            "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                            "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="Figure1.pdf", width = 8, height = 6, units = "in")

##############
## Figure 2 ##
##############

# White Democrats

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + 
           imce_smgov + imce_relgs + imce_noeql + imce_upper + 
           imce_badpr, data = df_imce[df_imce$pid_white == "White Democrat", ])
m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + 
           imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + 
           age + educ + faminc_new + female + ideo, 
         data = df_imce[df_imce$pid_white == "White Democrat", ])

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "No Controls"

m2 <- tidy(m2, conf.int = TRUE)
m2 <- m2 %>% filter(grepl("imce", term))
m2$model <- "Controls"

m3 <- rbind(m1,m2)

m3 <- m3 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m3 <- m3 %>% filter(term != "(Intercept)") 
m3$cat <- "White Democrat"

# Non-White Democrats

m4 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + 
           imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, 
         data = df_imce[df_imce$pid_white == "Non-White Democrat", ])
m5 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + 
           imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + 
           age + educ + faminc_new + female + ideo, 
         data = df_imce[df_imce$pid_white == "Non-White Democrat", ])

m4 <- tidy(m4, conf.int = TRUE)
m4$model <- "No Controls"

m5 <- tidy(m5, conf.int = TRUE)
m5 <- m5 %>% filter(grepl("imce", term))
m5$model <- "Controls"

m6 <- rbind(m4,m5)

m6 <- m6 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m6 <- m6 %>% filter(term != "(Intercept)") 
m6$cat <- "Non-White Democrat"


# White Republicans

m7 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + 
           imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, 
         data = df_imce[df_imce$pid_white == "White Republican", ])
m8 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + 
           imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + 
           age + educ + faminc_new + female + ideo, 
         data = df_imce[df_imce$pid_white == "White Republican", ])

m7 <- tidy(m7, conf.int = TRUE)
m7$model <- "No Controls"

m8 <- tidy(m8, conf.int = TRUE)
m8 <- m8 %>% filter(grepl("imce", term))
m8$model <- "Controls"

m9 <- rbind(m7,m8)

m9 <- m9 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m9 <- m9 %>% filter(term != "(Intercept)") 
m9$cat <- "White Republican"

pid <- rbind(m3,m6,m9)
pid$cat <- factor(pid$cat, levels = c("White Democrat","Non-White Democrat",
                                      "White Republican"))

a <- pid %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = model)) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=8), legend.box.spacing = unit(0, "cm")) +
  facet_wrap(~cat) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/Figure2.pdf", width = 8, height = 6, units = "in")  

###############
## Figure A2 ##
###############

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + 
           conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, 
         id = ~respid, estimate = "amce")

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

m1$BY <- "Full Sample"
m1$BY2 <- "Full Sample"

n1 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology",
                      "Religiosity", "Racial Ideology", "Social Class", 
                      "Personal Traits"))
n4 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", 
                      "Economic Ideology:", "Religiosity:", "Racial Ideology:", 
                      "Social Class:", "Personal Traits:"))
n5 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c("Full Sample","Full Sample","Full Sample","Full Sample",
                       "Full Sample","Full Sample","Full Sample","Full Sample",
                       "Full Sample"))
n12 <- as.data.frame(c("Full Sample","Full Sample","Full Sample","Full Sample",
                       "Full Sample","Full Sample","Full Sample","Full Sample",
                       "Full Sample"))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("outcome","statistic","feature","level","estimate",
                  "std.error","z","p","lower","upper","BY","BY2")

whole <- rbind(m1,m2)

a <- whole %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                              "Gender:", "     Male","     Female",
                                                                              "Race:","     White","     Non-White",
                                                                              "Education:","     No College","     College",
                                                                              "Religiosity:","     Religious","     Non-Religious",
                                                                              "Social Class:","     Upper Class","     Middle/Working Class",
                                                                              "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                              "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                              "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA2.pdf", width = 6, height = 5, units = "in")

###############
## Figure A3 ##
###############

# White

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~white)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

n1 <- as.data.frame(c("White","White","White","White","White","White","White","White","White"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White

n1 <- as.data.frame(c("Non-White","Non-White","Non-White","Non-White","Non-White","Non-White","Non-White","Non-White","Non-White"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

m4 <- rbind(m1,m2,m3)
m4$BY <- factor(m4$BY, levels = c("White","Non-White"))


a <- m4 %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                           "Gender:", "     Male","     Female",
                                                                           "Race:","     White","     Non-White",
                                                                           "Education:","     No College","     College",
                                                                           "Religiosity:","     Religious","     Non-Religious",
                                                                           "Social Class:","     Upper Class","     Middle/Working Class",
                                                                           "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                           "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                           "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA3.pdf", width = 8, height = 6, units = "in")

###############
## Figure A4 ##
###############

# Democrat 

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~pid3_new)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

n1 <- as.data.frame(c("Democrat","Democrat","Democrat","Democrat","Democrat","Democrat","Democrat","Democrat","Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Independent

n1 <- as.data.frame(c("Independent","Independent","Independent","Independent","Independent","Independent","Independent","Independent","Independent"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Republican

n1 <- as.data.frame(c("Republican","Republican","Republican","Republican","Republican","Republican","Republican","Republican","Republican"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m4 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m4) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

m5 <- rbind(m1,m2,m3,m4)

a <- m5 %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                           "Gender:", "     Male","     Female",
                                                                           "Race:","     White","     Non-White",
                                                                           "Education:","     No College","     College",
                                                                           "Religiosity:","     Religious","     Non-Religious",
                                                                           "Social Class:","     Upper Class","     Middle/Working Class",
                                                                           "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                           "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                           "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA4.pdf", width = 8, height = 6, units = "in")

###############
## Figure A5 ##
###############

# White Democrat

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~pid_white2)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

n1 <- as.data.frame(c("White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White Democrat

n1 <- as.data.frame(c("Non-White Democrat","Non-White Democrat","Non-White Democrat","Non-White Democrat","Non-White Democrat","Non-White Democrat","Non-White Democrat","Non-White Democrat","Non-White Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Republican

n1 <- as.data.frame(c("White Republican","White Republican","White Republican","White Republican","White Republican","White Republican","White Republican","White Republican","White Republican"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m4 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m4) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White Republican

n1 <- as.data.frame(c("Non-White Republican","Non-White Republican","Non-White Republican","Non-White Republican","Non-White Republican","Non-White Republican","Non-White Republican","Non-White Republican","Non-White Republican"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m5 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m5) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

pid <- rbind(m1,m2,m3,m4,m5)
pid$BY <- factor(pid$BY, levels = c("White Democrat","Non-White Democrat","White Republican","Non-White Republican"))

a <- pid %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                            "Gender:", "     Male","     Female",
                                                                            "Race:","     White","     Non-White",
                                                                            "Education:","     No College","     College",
                                                                            "Religiosity:","     Religious","     Non-Religious",
                                                                            "Social Class:","     Upper Class","     Middle/Working Class",
                                                                            "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                            "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                            "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA5.pdf", width = 8, height = 8, units = "in")

###############
## Figure A6 ##
###############

# White Democrat

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~pid_wbo)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

n1 <- as.data.frame(c("White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat","White Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Black Democrat

n1 <- as.data.frame(c("Black Democrat","Black Democrat","Black Democrat","Black Democrat","Black Democrat","Black Democrat","Black Democrat","Black Democrat","Black Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Other Democrat

n1 <- as.data.frame(c("Other Democrat","Other Democrat","Other Democrat","Other Democrat","Other Democrat","Other Democrat","Other Democrat","Other Democrat","Other Democrat"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m4 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m4) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

pid <- rbind(m1,m2,m3,m4)

pid$BY <- factor(pid$BY, levels = c("White Democrat","Black Democrat","Other Democrat"))

a <- pid %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                            "Gender:", "     Male","     Female",
                                                                            "Race:","     White","     Non-White",
                                                                            "Education:","     No College","     College",
                                                                            "Religiosity:","     Religious","     Non-Religious",
                                                                            "Social Class:","     Upper Class","     Middle/Working Class",
                                                                            "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                            "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                            "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA6.pdf", width = 8, height = 6, units = "in")

###############
## Figure A7 ##
###############

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~rr_scale_cat2)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

# High RR

n1 <- as.data.frame(c("High Racial Resentment","High Racial Resentment","High Racial Resentment","High Racial Resentment","High Racial Resentment","High Racial Resentment","High Racial Resentment","High Racial Resentment","High Racial Resentment"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Low RR

n1 <- as.data.frame(c("Low Racial Resentment","Low Racial Resentment","Low Racial Resentment","Low Racial Resentment","Low Racial Resentment","Low Racial Resentment","Low Racial Resentment","Low Racial Resentment","Low Racial Resentment"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

rr <- rbind(m1,m2,m3)
rr$BY <- factor(rr$BY, levels = c("Low Racial Resentment","High Racial Resentment"))

a <- rr %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                           "Gender:", "     Male","     Female",
                                                                           "Race:","     White","     Non-White",
                                                                           "Education:","     No College","     College",
                                                                           "Religiosity:","     Religious","     Non-Religious",
                                                                           "Social Class:","     Upper Class","     Middle/Working Class",
                                                                           "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                           "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                           "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA7.pdf", width = 8, height = 6, units = "in")

###############
## Figure A8 ##
###############

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~ar_scale_cat2)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

# High RR

n1 <- as.data.frame(c("High Anti Racism","High Anti Racism","High Anti Racism","High Anti Racism","High Anti Racism","High Anti Racism","High Anti Racism","High Anti Racism","High Anti Racism"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","ar_scale_cat2")

# Low RR

n1 <- as.data.frame(c("Low Anti Racism","Low Anti Racism","Low Anti Racism","Low Anti Racism","Low Anti Racism","Low Anti Racism","Low Anti Racism","Low Anti Racism","Low Anti Racism"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","ar_scale_cat2")

m4 <- rbind(m1,m2,m3)
m4$BY <- factor(m4$BY, levels = c("Low Anti Racism","High Anti Racism"))

a <- m4 %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                           "Gender:", "     Male","     Female",
                                                                           "Race:","     White","     Non-White",
                                                                           "Education:","     No College","     College",
                                                                           "Religiosity:","     Religious","     Non-Religious",
                                                                           "Social Class:","     Upper Class","     Middle/Working Class",
                                                                           "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                           "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                           "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA8.pdf", width = 8, height = 6, units = "in")

###############
## Figure A9 ##
###############

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~pid_white_rr)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

# White Democrat with Low RR

n1 <- as.data.frame(c("White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR","White Democrat with Low RR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Democrat with High RR

n1 <- as.data.frame(c("White Democrat with High RR","White Democrat with High RR","White Democrat with High RR","White Democrat with High RR","White Democrat with High RR","White Democrat with High RR","White Democrat with High RR","White Democrat with High RR","White Democrat with High RR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White Democrat with Low RR

n1 <- as.data.frame(c("Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR","Non-White Democrat with Low RR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m4 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m4) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White Democrat with High RR

n1 <- as.data.frame(c("Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR","Non-White Democrat with High RR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m5 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m5) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Republican with Low RR

n1 <- as.data.frame(c("White Republican with Low RR","White Republican with Low RR","White Republican with Low RR","White Republican with Low RR","White Republican with Low RR","White Republican with Low RR","White Republican with Low RR","White Republican with Low RR","White Republican with Low RR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m6 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m6) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Republican with High RR

n1 <- as.data.frame(c("White Republican with High RR","White Republican with High RR","White Republican with High RR","White Republican with High RR","White Republican with High RR","White Republican with High RR","White Republican with High RR","White Republican with High RR","White Republican with High RR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m7 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m7) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

rr <- rbind(m1,m2,m3,m4,m5,m6,m7)
rr$BY <- factor(rr$BY, levels = c("White Democrat with Low RR","White Democrat with High RR","Non-White Democrat with Low RR","Non-White Democrat with High RR","White Republican with Low RR","White Republican with High RR"))


a <- rr %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                           "Gender:", "     Male","     Female",
                                                                           "Race:","     White","     Non-White",
                                                                           "Education:","     No College","     College",
                                                                           "Religiosity:","     Religious","     Non-Religious",
                                                                           "Social Class:","     Upper Class","     Middle/Working Class",
                                                                           "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                           "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                           "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA9.pdf", width = 10, height = 10, units = "in")

################
## Figure A10 ##
################

m1 <- cj(df_amce, rate ~ conj_older + conj_males + conj_white + conj_nocol + conj_relgs + conj_upper + conj_smgov + conj_noeql + conj_badpr, id = ~respid, estimate = "amce", by = ~pid_white_ar)

m1$feature <- as.character(m1$feature)
m1$feature[m1$feature == "conj_older"] <- "Age"
m1$feature[m1$feature == "conj_males"] <- "Gender"
m1$feature[m1$feature == "conj_white"] <- "Race"
m1$feature[m1$feature == "conj_nocol"] <- "Education"
m1$feature[m1$feature == "conj_smgov"] <- "Economic Ideology"
m1$feature[m1$feature == "conj_relgs"] <- "Religiosity"
m1$feature[m1$feature == "conj_noeql"] <- "Racial Ideology"
m1$feature[m1$feature == "conj_upper"] <- "Social Class"
m1$feature[m1$feature == "conj_badpr"] <- "Personal Traits"

m1$level <- as.character(m1$level)
m1$level[m1$level == "Racially Conservative"] <- "     Racially Conservative"
m1$level[m1$level == "Economically Liberal"] <- "     Economically Liberal"
m1$level[m1$level == "College"] <- "     College"
m1$level[m1$level == "Female"] <- "     Female"
m1$level[m1$level == "Male"] <- "     Male"
m1$level[m1$level == "Middle/Working Class"] <- "     Middle/Working Class"
m1$level[m1$level == "Negative Traits"] <- "     Negative Traits"
m1$level[m1$level == "No College"] <- "     No College"
m1$level[m1$level == "Non-Religious"] <- "     Non-Religious"
m1$level[m1$level == "Non-White"] <- "     Non-White"
m1$level[m1$level == "Old"] <- "     Old"
m1$level[m1$level == "Positive Traits"] <- "     Positive Traits"
m1$level[m1$level == "Racially Liberal"] <- "     Racially Liberal"
m1$level[m1$level == "Religious"] <- "     Religious"
m1$level[m1$level == "Economically Conservative"] <- "     Economically Conservative"
m1$level[m1$level == "Upper Class"] <- "     Upper Class"
m1$level[m1$level == "White"] <- "     White"
m1$level[m1$level == "Young"] <- "     Young"

colnames(m1)[12] <- "BY2"

# White Democrat with Low AR

n1 <- as.data.frame(c("White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR","White Democrat with Low AR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m2 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m2) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Democrat with High AR

n1 <- as.data.frame(c("White Democrat with High AR","White Democrat with High AR","White Democrat with High AR","White Democrat with High AR","White Democrat with High AR","White Democrat with High AR","White Democrat with High AR","White Democrat with High AR","White Democrat with High AR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m3 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m3) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White Democrat with Low AR

n1 <- as.data.frame(c("Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR","Non-White Democrat with Low AR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m4 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m4) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# Non-White Democrat with High AR

n1 <- as.data.frame(c("Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR","Non-White Democrat with High AR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m5 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m5) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Republican with Low AR

n1 <- as.data.frame(c("White Republican with Low AR","White Republican with Low AR","White Republican with Low AR","White Republican with Low AR","White Republican with Low AR","White Republican with Low AR","White Republican with Low AR","White Republican with Low AR","White Republican with Low AR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m6 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m6) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

# White Republican with High AR

n1 <- as.data.frame(c("White Republican with High AR","White Republican with High AR","White Republican with High AR","White Republican with High AR","White Republican with High AR","White Republican with High AR","White Republican with High AR","White Republican with High AR","White Republican with High AR"))
n2 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n3 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n4 <- as.data.frame(c("Age", "Gender", "Race", "Education", "Economic Ideology", "Religiosity", "Racial Ideology", "Social Class", "Personal Traits"))
n5 <- as.data.frame(c("Age:", "Gender:", "Race:", "Education:", "Economic Ideology:", "Religiosity:", "Racial Ideology:", "Social Class:", "Personal Traits:"))
n6 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n7 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n8 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n9 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n10 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n11 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))
n12 <- as.data.frame(c(NA,NA,NA,NA,NA,NA,NA,NA,NA))

m7 <- cbind(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)
colnames(m7) <- c("BY","outcome","statistic","feature","level","estimate","std.error","z","p","lower","upper","BY2")

rr <- rbind(m1,m2,m3,m4,m5,m6,m7)
rr$BY <- factor(rr$BY, levels = c("White Democrat with Low AR","White Democrat with High AR","Non-White Democrat with Low AR","Non-White Democrat with High AR","White Republican with Low AR","White Republican with High AR"))

a <- rr %>% ggplot(aes(x = estimate,  y = fct_rev(factor(level, levels = c("Age:", "     Old", "     Young",
                                                                           "Gender:", "     Male","     Female",
                                                                           "Race:","     White","     Non-White",
                                                                           "Education:","     No College","     College",
                                                                           "Religiosity:","     Religious","     Non-Religious",
                                                                           "Social Class:","     Upper Class","     Middle/Working Class",
                                                                           "Economic Ideology:","     Economically Conservative","     Economically Liberal",
                                                                           "Racial Ideology:","     Racially Conservative","     Racially Liberal",
                                                                           "Personal Traits:","     Negative Traits","     Positive Traits"))))) +
  geom_vline(xintercept = 0, linetype="dashed") +
  geom_pointrange(aes(xmin = lower, xmax = upper), size=0.2) +
  labs(x = "AMCE Estimates", y = "") +
  scale_colour_grey(start = 0.2, end = 0.7) +
  theme_bw() +
  theme(legend.position="bottom") +
  facet_wrap(~BY) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA10.pdf", width = 10, height = 10, units = "in")

################
## Figure A11 ##
################

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce)

m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo, data = df_imce)

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "No Controls"

m2 <- tidy(m2, conf.int = TRUE)
m2 <- m2 %>% filter(grepl("imce", term))
m2$model <- "Controls"

whole <- rbind(m1,m2)

whole <- whole %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

whole <- whole %>% filter(term != "(Intercept)") 
whole$cat <- "Full Sample"

a <- whole %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = model)) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=8), legend.box.spacing = unit(0, "cm")) +
  facet_wrap(~cat) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA11.pdf", width = 6, height = 5, units = "in")  

################
## Figure A12 ##
################

# Control for RR

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo + rr_scale, data = df_imce)

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "Control for Racial Resentment"
m1 <- m1 %>% filter(grepl("imce", term))

m1 <- m1 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

# Control for AR

m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo + ar_scale, data = df_imce)

m2 <- tidy(m2, conf.int = TRUE)
m2$model <- "Control for Anti Racism"
m2 <- m2 %>% filter(grepl("imce", term))

m2 <- m2 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m3 <- rbind(m1,m2)

a <- m3 %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = factor(model, levels = c("Control for Racial Resentment","Control for Anti Racism")))) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=6), legend.box.spacing = unit(0, "cm")) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA12.pdf", width = 6, height = 5, units = "in")  

################
## Figure A13 ##
################

# Whites

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$white == "White", ])

m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + female + pid7_r + ideo, data = df_imce[df_imce$white == "White", ])

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "No Controls"

m2 <- tidy(m2, conf.int = TRUE)
m2 <- m2 %>% filter(grepl("imce", term))
m2$model <- "Controls"

m3 <- rbind(m1,m2)

m3 <- m3 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m3 <- m3 %>% filter(term != "(Intercept)") 
m3$cat <- "White"

# Non-Whites

m4 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$white == "Non-White", ])

m5 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + female + pid7_r + ideo, data = df_imce[df_imce$white == "Non-White", ])

m4 <- tidy(m4, conf.int = TRUE)
m4$model <- "No Controls"

m5 <- tidy(m5, conf.int = TRUE)
m5 <- m5 %>% filter(grepl("imce", term))
m5$model <- "Controls"

m6 <- rbind(m4,m5)

m6 <- m6 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m6 <- m6 %>% filter(term != "(Intercept)") 
m6$cat <- "Non-White"

m7 <- rbind(m3,m6)
m7$cat <- factor(m7$cat, levels = c("White","Non-White"))

a <- m7 %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = model)) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=8), legend.box.spacing = unit(0, "cm")) +
  facet_wrap(~cat) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA13.pdf", width = 6, height = 5, units = "in")  

################
## Figure A14 ##
################

# Democrats

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$pid3_new == "Democrat", ])

m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + ideo, data = df_imce[df_imce$pid3_new == "Democrat", ])

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "No Controls"

m2 <- tidy(m2, conf.int = TRUE)
m2 <- m2 %>% filter(grepl("imce", term))
m2$model <- "Controls"

m3 <- rbind(m1,m2)

m3 <- m3 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m3 <- m3 %>% filter(term != "(Intercept)") 
m3$cat <- "Democrat"

# Independents

m4 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$pid3_new == "Independent", ])

m5 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + ideo, data = df_imce[df_imce$pid3_new == "Independent", ])

m4 <- tidy(m4, conf.int = TRUE)
m4$model <- "No Controls"

m5 <- tidy(m5, conf.int = TRUE)
m5 <- m5 %>% filter(grepl("imce", term))
m5$model <- "Controls"

m6 <- rbind(m4,m5)

m6 <- m6 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m6 <- m6 %>% filter(term != "(Intercept)") 
m6$cat <- "Indepedent"

# Republicans

m7 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$pid3_new == "Republican", ])

m8 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + ideo, data = df_imce[df_imce$pid3_new == "Republican", ])

m7 <- tidy(m7, conf.int = TRUE)
m7$model <- "No Controls"

m8 <- tidy(m8, conf.int = TRUE)
m8 <- m8 %>% filter(grepl("imce", term))
m8$model <- "Controls"

m9 <- rbind(m7,m8)

m9 <- m9 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m9 <- m9 %>% filter(term != "(Intercept)") 
m9$cat <- "Republican"

m10 <- rbind(m3,m6,m9)
m10$cat <- factor(m10$cat, levels = c("Democrat","Indepedent","Republican"))

a <- m10 %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = model)) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=8), legend.box.spacing = unit(0, "cm")) +
  facet_wrap(~cat) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA14.pdf", width = 8, height = 6, units = "in")  

################
## Figure A15 ##
################

# Low RR

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$rr_scale_cat2 == "Low Racial Resentment", ])

m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo, data = df_imce[df_imce$rr_scale_cat2 == "Low Racial Resentment", ])

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "No Controls"

m2 <- tidy(m2, conf.int = TRUE)
m2 <- m2 %>% filter(grepl("imce", term))
m2$model <- "Controls"

m3 <- rbind(m1,m2)

m3 <- m3 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m3 <- m3 %>% filter(term != "(Intercept)") 
m3$cat <- "Low Racial Resentment"


# High RR

m4 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$rr_scale_cat2 == "High Racial Resentment", ])

m5 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo, data = df_imce[df_imce$rr_scale_cat2 == "High Racial Resentment", ])

m4 <- tidy(m4, conf.int = TRUE)
m4$model <- "No Controls"

m5 <- tidy(m5, conf.int = TRUE)
m5 <- m5 %>% filter(grepl("imce", term))
m5$model <- "Controls"

m6 <- rbind(m4,m5)

m6 <- m6 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m6 <- m6 %>% filter(term != "(Intercept)") 
m6$cat <- "High Racial Resentment"

rr <- rbind(m3,m6)
rr$cat <- factor(rr$cat, levels = c("Low Racial Resentment","High Racial Resentment"))

a <- rr %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = model)) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=8), legend.box.spacing = unit(0, "cm")) +
  facet_wrap(~cat) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA15.pdf", width = 6, height = 5, units = "in")  

################
## Figure A16 ##
################

# Anti-racism

# Low AR

m1 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$ar_scale_cat2 == "Low Anti Racism", ])

m2 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo, data = df_imce[df_imce$ar_scale_cat2 == "Low Anti Racism", ])

m1 <- tidy(m1, conf.int = TRUE)
m1$model <- "No Controls"

m2 <- tidy(m2, conf.int = TRUE)
m2 <- m2 %>% filter(grepl("imce", term))
m2$model <- "Controls"

m3 <- rbind(m1,m2)

m3 <- m3 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m3 <- m3 %>% filter(term != "(Intercept)") 
m3$cat <- "Low Anti Racism"

# High AR

m4 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr, data = df_imce[df_imce$ar_scale_cat2 == "High Anti Racism", ])

m5 <- lm(ft_rep ~ imce_older + imce_males + imce_white + imce_nocol + imce_smgov + imce_relgs + imce_noeql + imce_upper + imce_badpr + age + educ + faminc_new + white + female + pid7_r + ideo, data = df_imce[df_imce$ar_scale_cat2 == "High Anti Racism", ])

m4 <- tidy(m4, conf.int = TRUE)
m4$model <- "No Controls"

m5 <- tidy(m5, conf.int = TRUE)
m5 <- m5 %>% filter(grepl("imce", term))
m5$model <- "Controls"

m6 <- rbind(m4,m5)

m6 <- m6 %>% 
  relabel_predictors(c("imce_older" = "Old", 
                       "imce_males" = "Male",
                       "imce_white" = "White",
                       "imce_nocol" = "No College",
                       "imce_smgov" = "Economically Conservative",
                       "imce_relgs" = "Religious",
                       "imce_noeql" = "Racially Conservative",
                       "imce_upper" = "Upper Class",
                       "imce_badpr" = "Negative Traits"))

m6 <- m6 %>% filter(term != "(Intercept)") 
m6$cat <- "High Anti Racism"

ar <- rbind(m3,m6)
ar$cat <- factor(ar$cat, levels = c("Low Anti Racism","High Anti Racism"))

a <- ar %>% 
  ggplot(aes(x = estimate, y = fct_rev(factor(term, levels = c("Old", "Male","White","No College","Religious","Upper Class","Economically Conservative","Racially Conservative","Negative Traits"))), color = model)) +
  geom_vline(xintercept = 0, linetype="dashed", color = "gray") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), size=0.3, position=position_dodge(width=c(0.5))) +
  labs(x = "Coefficient Estimates", y = "IMCE", color = "") +
  scale_colour_grey(start = 0.2, end = 0.6) +
  theme_bw() +
  theme(legend.position="bottom", legend.text = element_text(size=8), legend.box.spacing = unit(0, "cm")) +
  facet_wrap(~cat) +
  theme(axis.text.y=element_text(hjust=0))

ggsave(a,file="~/Desktop/FigureA16.pdf", width = 6, height = 5, units = "in")  

